package chapter4.section5;

/**
 * 程序 4-7：冒泡排序
 *
 * @author 张玮婷 20245080902061
 */

public class BubbleSortApp {
    public static void main(String[] args) {
        int[] arr = {51, 38, 49, 27, 62, 5, 16};
        int i, j, temp, len;
        len = arr.length;
        for (i = len - 1; i > 0; i--) {
            for (j = 0; j < i; j++) {
                if (arr[j] > arr[j + 1]) {
                    // 进行数据交换
                    temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
        System.out.println("冒泡排序的结果是");
        for (i = 0; i < len; i++) {
            System.out.print(arr[i] + " ");
        }
    }
}
